package me.wangxuan.pat;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimplePostman extends JFrame {
	private static final long serialVersionUID = 1L;
	private JTabbedPane tabbedPane;
	    private JTextField urlTextField;
	    private JComboBox<String> methodComboBox;
	    private JTextArea headersTextArea;
	    private JTextArea bodyTextArea;
	    private JTextArea responseTextArea;
	    private JButton sendButton;

	    public SimplePostman() {
	        setTitle("Simple Postman");
	        setSize(800, 600);
	        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        setLayout(new BorderLayout());

	        tabbedPane = new JTabbedPane();
	        add(tabbedPane, BorderLayout.CENTER);

	        // Request Tab
	        JPanel requestPanel = new JPanel(new GridLayout(5, 1));
	        tabbedPane.addTab("Request", requestPanel);

	        requestPanel.add(new JLabel("URL:"));
	        urlTextField = new JTextField("http://");
	        requestPanel.add(urlTextField);

	        requestPanel.add(new JLabel("Method:"));
	        methodComboBox = new JComboBox<>(new String[]{"GET", "POST", "PUT", "DELETE"});
	        requestPanel.add(methodComboBox);

	        requestPanel.add(new JLabel("Headers:"));
	        headersTextArea = new JTextArea(5, 20);
	        requestPanel.add(new JScrollPane(headersTextArea));

	        requestPanel.add(new JLabel("Body:"));
	        bodyTextArea = new JTextArea(5, 20);
	        requestPanel.add(new JScrollPane(bodyTextArea));

	        // Response Tab
	        responseTextArea = new JTextArea(20, 50);
	        tabbedPane.addTab("Response", new JScrollPane(responseTextArea));

	        // Send Button
	        sendButton = new JButton("Send");
	        sendButton.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                sendRequest();
	            }
	        });

	        JPanel buttonPanel = new JPanel();
	        buttonPanel.add(sendButton);
	        add(buttonPanel, BorderLayout.SOUTH);
	    }

	    private void sendRequest() {
	        // Here you would add the code to send the HTTP request
	        // For now, we just print the request details to the response text area
	        String requestDetails = "URL: " + urlTextField.getText() + "\n" +
	                                "Method: " + methodComboBox.getSelectedItem() + "\n" +
	                                "Headers: " + headersTextArea.getText() + "\n" +
	                                "Body: " + bodyTextArea.getText();
	        responseTextArea.setText(requestDetails);
	        // TODO: Send HTTP request and update responseTextArea with the response
	    }

	    public static void main(String[] args) {
	        SwingUtilities.invokeLater(new Runnable() {
	            @Override
	            public void run() {
	                new SimplePostman().setVisible(true);
	            }
	        });
	    }
}
